package cn.wolfcode.wolf2w.service.impl;

import cn.wolfcode.wolf2w.domain.SpotDetail;
import cn.wolfcode.wolf2w.repository.SpotDetailRepository;
import cn.wolfcode.wolf2w.service.ISpotDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.List;

@Service
public class SpotDetailServiceImpl implements ISpotDetailService {

    @Autowired
    private MongoTemplate template;
    @Autowired
    private SpotDetailRepository repository ;
    @Override
    public void save(SpotDetail spotDetail) {
        spotDetail.setId(null);
        repository.save(spotDetail);
    }

    @Override
    public void update(SpotDetail spotDetail) {
        repository.save(spotDetail);
    }

    @Override
    public void delete(String id) {
        repository.deleteById(id);
    }

    @Override
    public SpotDetail get(String id) {
        return repository.findById(id).orElse(null);
    }

    @Override
    public List<SpotDetail> list() {
        return repository.findAll();
    }

    @Override
    public SpotDetail getDetailBySpotId(String id) {
        if(StringUtils.hasLength(id)){
            SpotDetail spotDetail= repository.findBySpotId(id);
            return spotDetail;
        }
        return null ;
    }

}
